package com.gangan.controller.web;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gangan.controller.common.BaseController;
import com.gangan.model.Activity;
import com.gangan.model.CmsContent;
import com.gangan.service.IActivityService;
import com.gangan.service.ICmsContentService;
import com.gangan.tools.MessageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "*活动模块控制层")
@RestController
@RequestMapping("/activity")
public class ActivityController extends BaseController {

    @Autowired
    IActivityService activityService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value="数据列表", notes="根据相关条件查询列表数据")
    public MessageBean list(Page page){
        return resultSuccess(activityService.page(page, Wrappers.<Activity>query().lambda().orderByDesc(Activity::getCreateTime)));
    }

    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ApiOperation(value="移除数据", notes="根据自增主键移除数据")
    public MessageBean del(Integer id){
        return resultSuccess(activityService.removeById(id));
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value="新增数据", notes="将提交的数据保存到数据库")
    public MessageBean add(Activity add){
        return resultSuccess(activityService.save(add));
    }

    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    @ApiOperation(value="编辑数据", notes="根据主键修改数据")
    public MessageBean edit(Activity edit){
        return resultSuccess(activityService.updateById(edit));
    }

    @RequestMapping(value = "/getActivityByStartTimeorLabel",method = RequestMethod.GET)
    @ApiOperation(value="根据标题和status查询活动数据列表 status 0：即将开始 1：已结束", notes="根据标题和status查询活动数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "label", dataType = "String", required = false, value = "标题模糊查询条件"),
            @ApiImplicitParam(paramType = "query", name = "status", dataType = "Integer", required = false, value = "status", defaultValue = "0")})
    public MessageBean getActivityByStartTimeorLabel(Page page,String label, Integer status){
        try{
            return  resultSuccess(activityService.getActivityByStartTimeorLabel(page,label,status));
        }catch(Exception e){
            return   resultFailed();
        }
    }

}
